// pages/main/EnterpriseEntry.js
import api from "../../utils/api.js";
import utils from "../../utils/utils.js";
import network from "../../utils/network.js";
let app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    enterpriseInfo: null,
    notice: [{
      id: 1,
      title: '公安县科技服务平台上线了'
    }, {
      id: 2,
      title: '公安县科技服务平台上线了'
    }],
    dongtai: [],
    policy: [],
    cadre: [{
      imgurl: '',
      enterprise: '县商务局',
      name: '张三'
    }, {
      imgurl: '',
      enterprise: '县商务局',
      name: '张三'
    }, {
      imgurl: '',
      enterprise: '县商务局',
      name: '张三'
    }, {
      imgurl: '',
      enterprise: '县商务局',
      name: '张三'
    }, {
      imgurl: '',
      enterprise: '县商务局',
      name: '张三'
    }],
    x: 0,
    y: 0,
    animation: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      x: utils.windowSize().winWidth - 60,
      y: utils.windowSize().winHeight - 180
    })

    network.postJson(this, api.zhuqiIndex).then(res => {
      this.setData({
        dongtai: res.data.data.dongtai,
        policy: res.data.data.zhengce,
        cadre: res.data.data.ganbu,
        notice: res.data.data.notice
      })
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // let enterpriseInfo = wx.getStorageSync('jinxin_enterprise_info')
    // if (enterpriseInfo) {
    //   this.setData({
    //     enterpriseInfo: enterpriseInfo
    //   })
    // } else {
    //   wx.navigateTo({
    //     url: '/myself/login/Login',
    //   })
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  /**
  * 公告
  */
  bindChange: function (e) {
    let index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '/home/notice/Notice?notice=' + JSON.stringify(this.data.notice[index])
    })
  },

  onNavigateItemClick: function(e) {
    let type = e.currentTarget.dataset.type;
    let path = '/home/enterprise/EnterpriseCategory';
    switch (type) {
      case 4:
        path = '/home/enterprise/EnterpriseCategory';
        break;
      case 5:
        path = '/policy/policy/PolicyList?index=' + type + '&page=0'
        break;
      case 6:
        path = '/policy/cadre/Cadre';
        break;
        case 10:
        path = '/pages/main/ZhuqiDongtai';
        break;
    }
    wx.navigateTo({
      url: path
    })
  },

  goZhuqiDongtaiDetails(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/main/ZhuqiDongtaiDetails?id=' + id
    })
  },

  goPolicyDetails(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/policy/policy/PolicyDetails?id=' + id
    })
  },

  detailsTap(e) {
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: '/policy/cadre/CadreDetails?id=' + id + '&name=' + name
    })
  },
  goWorkList() {
    if (app.globalData.userInfo) {
      wx.navigateTo({
        url: '/myself/daily/WorkList'
      })
    } else {
      wx.navigateTo({
        url: '/myself/login/Login'
      })
    }
  }
})